#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 2e5 + 5;
int h[N], e[N], ne[N], w[N], in[N], ans[N], idx;
void add(int a, int b, int c)
{
	e[idx] = b; w[idx] = c; in[b]++; ne[idx] = h[a]; h[a] = idx++;
}

int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n; idx = 0;
		for (int i = 0; i <= n; ++i)
		{
			h[i] = -1; in[i] = 0;
		}
		for (int i = 1; i < n; ++i)
		{
			int a, b, c, d; cin >> a >> b >> c >> d;
			if (c > d) add(a, b, c - d);
			else add(b, a, d - c);
		}
		queue<int> q;
		for (int i = 1; i <= n; ++i) if (in[i] == 0) q.push(i);
		int cnt = n;
		while (q.size())
		{
			int cur = q.front(); q.pop(); ans[cur] = cnt--;
			//cout << "cur = " << cur << endl;
			for (int i = h[cur]; i != -1; i = ne[i])
			{
				int j = e[i];
				if (--in[j] == 0) q.push(j);
			}
		}
		for (int i = 1; i <= n; ++i) cout << ans[i] << ' '; cout << endl;
	}
	return 0;
}